#include "c13265-07a.h"

#define CS_Port GPIOB
#define CS_Pin LL_GPIO_PIN_0
#define RESET_Port GPIOB
#define RESET_Pin LL_GPIO_PIN_1
#define A0_Port GPIOB
#define A0_Pin LL_GPIO_PIN_2
#define WR_Port GPIOB
#define WR_Pin LL_GPIO_PIN_3
#define RD_Port GPIOB
#define RD_Pin LL_GPIO_PIN_4

/*----------------------------------------------------------*/
/*     定义 CPU  PORT                             */
/*----------------------------------------------------------*/
/*#define PORT P1
#define CS P20
#define RESET P21
#define RS P22
#define WR P23
#define RD P24*/

/*-------------------------------------------------------------*/
uint8_t page1;
uint8_t column1;
uint16_t wait;
/*-------------------------------------------------------------*/
/*定义延迟时间常数                                             */
/*-------------------------------------------------------------*/
#define EEDLY 8
#define DSDLY 5
#define CMDLY 200

void _nop_(void)
{
	uint8_t a = 0;
	for (uint8_t i = 0; i < 0xff; i++) {
		a = i;
		a = a;
	}
}
/*-------------------------------------------------------------*/
/*涵数原形定义                                                 */
/*-------------------------------------------------------------*/

/*-------------------------------------------------------------*/
/*------------------------IMAGE DATA---------------------------*/
uint8_t IMAGE0[] = {/*--  调入了一幅图像：d:\My Documents\桌面\Co0157A\12856A.bmp  --*/
		    /*--  调入了一幅图像：d:\My Documents\桌面\13265A.bmp  --*/
		    /*--  宽度x高度=132x65  --*/
		    /*--  高度不是8的倍数，现调整为：宽度x高度=132x72  --*/
		    0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0xF1, 0x11, 0x01, 0x11, 0xF1, 0x11, 0x01,
		    0x81, 0x81, 0x91, 0x01, 0x01, 0x01, 0x01, 0x01, 0x81, 0x81, 0x81, 0x81, 0x01, 0x81, 0x81, 0xE1,
		    0x81, 0x81, 0x01, 0x01, 0x01, 0x81, 0x81, 0x01, 0x81, 0x81, 0x01, 0x01, 0x01, 0x81, 0x81, 0x81,
		    0x01, 0x01, 0x81, 0x81, 0x81, 0x01, 0x81, 0x81, 0x81, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x31, 0x11, 0x11, 0xF1, 0x11, 0x01, 0x11, 0xF1, 0x11, 0x01,
		    0x01, 0x01, 0x01, 0x01, 0x01, 0x21, 0xF1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		    0x01, 0x01, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x11, 0x01,
		    0x11, 0x1F, 0x10, 0x00, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x00, 0x00, 0x19, 0x12, 0x12, 0x14, 0x09,
		    0x00, 0x00, 0x00, 0x0F, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x11, 0x10, 0x00, 0x00, 0x00,
		    0x0F, 0x10, 0x10, 0x10, 0x0F, 0x00, 0x40, 0x41, 0x66, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00,
		    0x10, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x00, 0x00, 0x00, 0x10, 0x1F, 0x10, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0xF1, 0x09, 0x09, 0x09,
		    0xF1, 0x01, 0x01, 0x01, 0x11, 0xF9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		    0x09, 0xF9, 0x49, 0x49, 0x49, 0xB1, 0x01, 0x01, 0x81, 0x41, 0x41, 0x41, 0x81, 0x01, 0x41, 0x41,
		    0xF1, 0x41, 0x41, 0x01, 0x01, 0x41, 0x41, 0xF1, 0x41, 0x41, 0x01, 0x01, 0x01, 0x81, 0x41, 0x41,
		    0x41, 0x81, 0x01, 0x01, 0x41, 0xC1, 0x81, 0x41, 0x41, 0x01, 0x41, 0xC1, 0x41, 0x01, 0x41, 0xC1,
		    0x41, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xE1, 0x19, 0xE1, 0x01, 0x01, 0x09,
		    0xF9, 0x41, 0x41, 0x41, 0x81, 0x01, 0x01, 0x81, 0x41, 0x41, 0x41, 0xC1, 0x01, 0x01, 0x81, 0x41,
		    0x41, 0x41, 0x81, 0x01, 0x41, 0xC1, 0x81, 0x41, 0x41, 0x81, 0x01, 0x41, 0x41, 0xF1, 0x41, 0x41,
		    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x00,
		    0x07, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x04, 0x0A, 0x09, 0x09,
		    0x0F, 0x08, 0x00, 0x00, 0x07, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0x08, 0x00, 0x00,
		    0x00, 0x07, 0x09, 0x09, 0x09, 0x05, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x08, 0x00, 0x00, 0x20, 0x20,
		    0x33, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x09, 0x01,
		    0x09, 0x0E, 0x08, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x07, 0x00, 0x00, 0x0C, 0x09, 0x09, 0x0A, 0x04,
		    0x00, 0x00, 0x07, 0x09, 0x09, 0x09, 0x05, 0x00, 0x08, 0x0F, 0x08, 0x00, 0x00, 0x0F, 0x08, 0x00,
		    0x00, 0x07, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
		    0xFF, 0x00, 0x00, 0x00, 0xFE, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x86, 0x41, 0x21, 0x11, 0x0E,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x09, 0x09, 0x09, 0xF6, 0x00, 0x00,
		    0x90, 0x48, 0x28, 0x28, 0xF0, 0x00, 0x08, 0x08, 0xFE, 0x08, 0x08, 0x00, 0x00, 0x08, 0x08, 0xFE,
		    0x08, 0x08, 0x00, 0x00, 0x00, 0xF0, 0x28, 0x28, 0x28, 0xB0, 0x00, 0x00, 0x08, 0xF8, 0x10, 0x08,
		    0x08, 0x00, 0x08, 0x18, 0x68, 0x80, 0x68, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0xC0, 0x3C, 0x23, 0x3C, 0xC0, 0x00, 0x01, 0xFF, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x90,
		    0x28, 0x28, 0x48, 0x98, 0x00, 0x00, 0xF0, 0x28, 0x28, 0x28, 0xB0, 0x00, 0x08, 0xF8, 0x10, 0x08,
		    0x08, 0xF0, 0x00, 0x08, 0x08, 0xFE, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x41, 0x41, 0x41, 0x80, 0x00, 0x00, 0x81,
		    0x41, 0x41, 0x41, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x41, 0x41,
		    0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
		    0x81, 0x41, 0x41, 0x41, 0x80, 0x00, 0x04, 0x84, 0x46, 0x41, 0x40, 0x80, 0x00, 0x00, 0x00, 0x80,
		    0xC0, 0x00, 0x00, 0x00, 0x01, 0x81, 0x41, 0x40, 0x41, 0x81, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01,
		    0x00, 0x00, 0x00, 0x81, 0x41, 0x41, 0x41, 0x80, 0x00, 0x00, 0xC0, 0x41, 0x41, 0x41, 0x40, 0x00,
		    0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0x40, 0x41, 0x41, 0x80, 0x00, 0x00, 0x00,
		    0x80, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40,
		    0x3F, 0x00, 0x00, 0x20, 0x40, 0x42, 0x42, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x1F, 0x20, 0x40, 0x40, 0x20, 0x1F, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00, 0x3C,
		    0x4A, 0x4A, 0x4A, 0x2C, 0x00, 0x42, 0x7E, 0x44, 0x02, 0x02, 0x7C, 0x40, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x61, 0x50, 0x48, 0x44, 0x43, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,
		    0x00, 0x00, 0x00, 0x40, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x61, 0x50, 0x48, 0x44, 0x43, 0x00, 0x04,
		    0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x37, 0x42,
		    0x42, 0x42, 0x3C, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x20, 0x40, 0x42, 0x42,
		    0x3D, 0x00, 0x00, 0x00, 0x40, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
		    0xFF, 0xFF, 0xFF, 0xFF

};

/*-------------------------------------------------------------*/
/*---------------- WRITE COMMAND PROGRAM ----------------------*/

void setcom(uint8_t par)
{
	//busy_flag();

	//RS = 0;
	LL_GPIO_ResetOutputPin(A0_Port, A0_Pin);
	_nop_();
	_nop_();
	//RD = 1;
	LL_GPIO_SetOutputPin(RD_Port, RD_Pin);
	_nop_();
	_nop_();
	//WR = 0;
	LL_GPIO_ResetOutputPin(WR_Port, WR_Pin);
	_nop_();
	_nop_();
	//PORT = par;
	LL_GPIO_WriteOutputPort(GPIOA, par);
	_nop_();
	_nop_();
	//RD = 1;
	LL_GPIO_SetOutputPin(RD_Port, RD_Pin);
	_nop_();
	_nop_();
	//WR = 1;
	LL_GPIO_SetOutputPin(WR_Port, WR_Pin);
	_nop_();
	_nop_();
	//RS = 1;
	LL_GPIO_SetOutputPin(A0_Port, A0_Pin);
	_nop_();
	_nop_();
	_nop_();
	_nop_();
}

/*------------------------------------------------------------*/
/*-------------WRITE DISPLAY DATA PROGRAM----------------*/

void Write_Bytedata(uint8_t par)
{
	//busy_flag();
	_nop_();
	_nop_();
	//RS = 1;
	LL_GPIO_SetOutputPin(A0_Port, A0_Pin);
	_nop_();
	_nop_();
	//WR = 0;
	LL_GPIO_ResetOutputPin(WR_Port, WR_Pin);
	_nop_();
	_nop_();
	//RD = 1;
	LL_GPIO_SetOutputPin(RD_Port, RD_Pin);
	_nop_();
	_nop_();
	//PORT = par;
	LL_GPIO_WriteOutputPort(GPIOA, par);
	_nop_();
	_nop_();
	//RS = 1;
	LL_GPIO_SetOutputPin(A0_Port, A0_Pin);
	_nop_();
	_nop_();
	//WR = 1;
	LL_GPIO_SetOutputPin(WR_Port, WR_Pin);
	_nop_();
	_nop_();
	//RD = 1;
	LL_GPIO_SetOutputPin(RD_Port, RD_Pin);
	_nop_();
	_nop_();
}

/*----------------INITALIZE PROGRAM---------------------------*/
void Initalize()
{
	setcom(0xe2);
	// setcom(0xae);/*set display off*/
	setcom(0xa1); /*set ADC=1 */
	setcom(0xc0); /*set SHL=1 */
	setcom(0xa2); /*set BIAS 1/6 */
	setcom(0xE0);
	setcom(0x2C);

	setcom(0x2E);
	setcom(0x2f); /*set VC VF VR on*/
	HAL_Delay(1000);
	setcom(0x24); /*SET (1+Ra/Rb)=6.0*/
	HAL_Delay(200);
	setcom(0x81); /*SET a=63*/
	setcom(0x2c); //old 0x2d
	HAL_Delay(200);
	setcom(0xD2);
	setcom(0x01);
	setcom(0x40);
	setcom(0xb0);
	setcom(0x10);
	setcom(0x00);
	setcom(0xD5);
	setcom(0x00);
	setcom(0xAD);
	setcom(0xFF);
	setcom(0xA6); /*SET DISPLAY NORMAL*/
	setcom(0xA4);
	setcom(0xAf);
	HAL_Delay(2000);
}
/*------------------------------------------------------------*/
/*----------------CLS SCREEN----------------------------------*/
void cls()
{
	uint8_t page, column;
	setcom(0xaf); /*SET DISPLAY ON*/
	for (page = 0xb0; page < 0xb9; page++) {
		setcom(page);
		setcom(0x10); /*set Y address*/
		setcom(0x00); /*set Y address*/
		for (column = 0; column < 132; column++) {
			Write_Bytedata(0x00);
		}
	}
}
void write_data(uint8_t *par)
{
	uint8_t page, column;
	setcom(0xaf); /*SET DISPLAY ON*/
	for (page = 0xb0; page < 0xb9; page++) {
		setcom(page);
		setcom(0x10); /*set Y address*/
		setcom(0x00); /*set Y address*/
		for (column = 0; column < 132; column++) {
			Write_Bytedata(*(par++));
		}
	}
}

/*--------------------------------------------------------------*/
/*----------------main program----------------------------------*/
void test()
{
	uint8_t page, column;
	uint8_t xscroll, yscroll;
	//uint8_t seg;
	//uint16_t num;

	//VDD = 0;  //VDD ON
	//VLED = 0; //VLED ON
	LL_GPIO_SetOutputPin(LCD3V3_EN_GPIO_Port, LCD3V3_EN_Pin);

	//CS = 0;
	LL_GPIO_ResetOutputPin(CS_Port, CS_Pin);
	//RESET = 0;
	LL_GPIO_ResetOutputPin(RESET_Port, RESET_Pin);
	HAL_Delay(2000);
	//RESET = 1;
	LL_GPIO_SetOutputPin(RESET_Port, RESET_Pin);
	//CS = 0;
	LL_GPIO_ResetOutputPin(CS_Port, CS_Pin);
	Initalize();
	setcom(0xaf); /*SET DISPLAY ON*/
	setcom(0x40); /*SET INITAL LINE*/
	setcom(0xb0); /*SET X ADDRESS*/
	setcom(0x10); /*SET Y ADDRESS*/
	setcom(0x00);
	//setcom(0xaf);/*SET DISPLAY OFF*/
	HAL_Delay(255);
	for (;;) {
		setcom(0xaf); /*SET DISPLAY ON*/
		setcom(0x40); /*SET INITAL LINE*/
		setcom(0xb0); /*SET X ADDRESS*/
		setcom(0x10); /*SET Y ADDRESS*/
		setcom(0x00);

		/*--------------------------------------------------*/
		/*-------------ENTIRE DISPLAY ON--------------------*/

		setcom(0xa5); /*entire  display on*/
		HAL_Delay(1000);

		setcom(0xa4); /*entire display off ,normal display on*/

		/*--------------------------------------------------*/
		/*-----------------X SCROLL-------------------------*/

		cls();
		setcom(0x40);
		for (page = 0xb0; page < 0xb9; page++) {
			setcom(page);
			setcom(0x10); /*set Y address*/
			setcom(0x00); /*set Y address*/
			for (column = 0; column < 132; column++) {
				Write_Bytedata(0x88);
			}
		}

		HAL_Delay(1000);
		for (xscroll = 0x40; xscroll < 0x44; xscroll++) {
			setcom(xscroll);

			HAL_Delay(125);
		}

		/*--------------------------------------------------*/
		/*----------------Y SCROLL---------------------------*/
		cls();
		setcom(0x40);
		for (yscroll = 0x00; yscroll < 0x04; yscroll++) {
			for (page = 0xb0; page < 0xb9; page++) {
				setcom(page);
				setcom(0x10);	 /*set Y address*/
				setcom(yscroll); /*set Y address*/
				for (column = 0; column < 132; column++) {
					if (column % 4 == 0)
						Write_Bytedata(0xff);
					else
						Write_Bytedata(0x00);
				}
			}

			HAL_Delay(125);

			cls();
		}

		/*--------------DISPLAY IMAGE ON-------------------------*/

		setcom(0x40); /*SET INITAL LINE*/
		write_data(IMAGE0);

		HAL_Delay(1250);

		cls();

		//VDD = 1;
		//VLED = 1;
		LL_GPIO_ResetOutputPin(LCD3V3_EN_GPIO_Port, LCD3V3_EN_Pin);
	}
}

/***************************************************************************************
 ***************************************************************************************
				AOI
 ***************************************************************************************
 ***************************************************************************************/

extern UART_HandleTypeDef huart1;

void C13265_07_powerOn(void)
{
	LL_GPIO_SetOutputPin(LCD3V3_EN_GPIO_Port, LCD3V3_EN_Pin);
	HAL_Delay(100);
}

void C13265_07_powerOff(void)
{
	//P1 = 0x00;
	LL_GPIO_WriteOutputPort(GPIOA, 0x00);
	//P2 = 0x00;
	LL_GPIO_WriteOutputPort(GPIOB, 0x00);
	//VDD = 1;
	LL_GPIO_ResetOutputPin(LCD3V3_EN_GPIO_Port, LCD3V3_EN_Pin);
	//P4 = 0xff;
	HAL_Delay(1000);
}

void C13265_07_reset(void)
{
	//RESET = 1;
	LL_GPIO_SetOutputPin(RESET_Port, RESET_Pin);
	HAL_Delay(20);
	//RESET = 0;
	LL_GPIO_ResetOutputPin(RESET_Port, RESET_Pin);
	HAL_Delay(20);
	//RESET = 1;
	LL_GPIO_SetOutputPin(RESET_Port, RESET_Pin);
	HAL_Delay(20);
	//RD = 1;
	HAL_Delay(20);
}

void _C13265_07_goToOrigin(void)
{
	setcom(0xaf); /*SET DISPLAY ON*/
	setcom(0x40); /*SET INITAL LINE*/
	setcom(0xb0); /*SET X ADDRESS*/
	setcom(0x10); /*SET Y ADDRESS*/
	setcom(0x00);
}

void fill(uint8_t byteData)
{
	uint8_t page, column;
	_C13265_07_goToOrigin();

	for (page = 0xb0; page < 0xb9; page++) {
		setcom(page);
		setcom(0x10); /*set Y address*/
		setcom(0x00); /*set Y address*/
		for (column = 0; column < 132; column++) {
			Write_Bytedata(byteData);
		}
	}
}
/*void write_data(uint8_t *par)
{
    uint8_t page, column;
    setcom(0xaf); 
    for (page = 0xb0; page < 0xb9; page++)
    {
        setcom(page);
        setcom(0x10);
        setcom(0x00);
        for (column = 0; column < 132; column++)
        {
            Write_Bytedata(*(par++));
        }
    }
}*/

/*----------------C13265_07_init PROGRAM---------------------------*/
void C13265_07_init()
{
	setcom(0xe2);
	// setcom(0xae);/*set display off*/
	setcom(0xa1); /*set ADC=1 */
	setcom(0xc0); /*set SHL=1 */
	setcom(0xa2); /*set BIAS 1/6 */
	setcom(0xE0);
	setcom(0x2C);

	setcom(0x2E);
	setcom(0x2f); /*set VC VF VR on*/
	HAL_Delay(20);
	setcom(0x24); /*SET (1+Ra/Rb)=6.0*/
	HAL_Delay(20);
	setcom(0x81); /*SET a=63*/
	setcom(0x2c); //old 0x2d
	HAL_Delay(20);
	setcom(0xD2);
	setcom(0x01);
	setcom(0x40);
	setcom(0xb0);
	setcom(0x10);
	setcom(0x00);
	setcom(0xD5);
	setcom(0x00);
	setcom(0xAD);
	setcom(0xFF);
	setcom(0xA6); /*SET DISPLAY NORMAL*/
	setcom(0xA4);
	setcom(0xAf);
	HAL_Delay(200);
	setcom(0xa4);
}

void C13265_07_full(void)
{
	fill(0xff);
}

void C13265_07_clear(void)
{
	fill(0x00);
}

void C13265_07_img1(void)
{
	fill(0x55);
}

void C13265_07_img2(void)
{
	fill(0xaa);
}

void C13265_07_img3(void)
{
	uint8_t page, column;
	_C13265_07_goToOrigin();

	for (page = 0xb0; page < 0xb9; page++) {
		setcom(page);
		setcom(0x10); /*set Y address*/
		setcom(0x00); /*set Y address*/
		for (column = 0; column < 132; column++) {
			if (column % 2 == 0)
				Write_Bytedata(0xff);
			else
				Write_Bytedata(0x00);
		}
	}
}

void C13265_07_img4(void)
{
	uint8_t page, column;
	_C13265_07_goToOrigin();

	for (page = 0xb0; page < 0xb9; page++) {
		setcom(page);
		setcom(0x10); /*set Y address*/
		setcom(0x00); /*set Y address*/
		for (column = 0; column < 132; column++) {
			if (column % 2 == 1)
				Write_Bytedata(0xff);
			else
				Write_Bytedata(0x00);
		}
	}
}

void keyWaitRelease(void)
{
	//key = 1;
	while (1) {
		//key = 1;
		HAL_Delay(5);

		if (!LL_GPIO_IsInputPinSet(KEY_GPIO_Port, KEY_Pin)) {
			//key = 1;
			HAL_Delay(25);
			if (!LL_GPIO_IsInputPinSet(KEY_GPIO_Port, KEY_Pin)) {
				while (!LL_GPIO_IsInputPinSet(KEY_GPIO_Port, KEY_Pin)) {
					HAL_Delay(5);
				}
				break;
			}
		}
	}
	/*while(key == 1){
		key = 1;
		HAL_Delay(20);
	}*/
}

void UartSendByte(uint8_t dat)
{
	uint8_t txb[1];
	txb[0] = dat;
	HAL_UART_Transmit(&huart1, txb, 1, HAL_MAX_DELAY);
}

void aoi(void)
{
	//uint8_t txb[64];

	uint8_t rxb = 0x00;
	uint8_t flagRunning = 0x01;
	C13265_07_powerOff();
	HAL_Delay(100);
	C13265_07_powerOn();
	C13265_07_reset();
	C13265_07_init();
	C13265_07_full();
	HAL_Delay(1000);

	for (;;) {
		rxb = 0x00;
		flagRunning = 0x01;

		HAL_Delay(100);
		C13265_07_powerOff();
		HAL_Delay(100);

		keyWaitRelease();
		HAL_Delay(100);
		C13265_07_powerOn();
		C13265_07_reset();
		C13265_07_init();
		C13265_07_full();
		UartSendByte(0x3F);
		//txb[0]
		//HAL_UART_Transmit(&huart1, )
		//C13265_07_powerOn();
		//HAL_Delay(2000);

		while (flagRunning == 0x01) {
			/*if(RI != 0){
            rxb = 0;
            rxb = SBUF;
            RI = 0;*/
			rxb = 0;
			HAL_UART_Receive(&huart1, &rxb, 1, 100);
			if (rxb != 0) {
				switch (rxb) {
				case 0x3E:
					flagRunning = 0;
					//SBUF = 0x3E;
					UartSendByte(0x3E);
					break;
				case 0x3F:
					C13265_07_full();
					//SBUF = 0x3F;
					UartSendByte(0x3F);
					break;
				case 0x30:
					C13265_07_clear();
					//SBUF = 0x30;
					UartSendByte(0x30);
					break;
				case 0x31:
					C13265_07_img1();
					//SBUF = 0x31;
					UartSendByte(0x31);
					break;
				case 0x32:
					C13265_07_img2();
					//SBUF = 0x32;
					UartSendByte(0x32);
					break;
				case 0x33:
					C13265_07_img3();
					//SBUF = 0x33;
					UartSendByte(0x33);
					break;
				case 0x34:
					C13265_07_img4();
					//SBUF = 0x34;
					UartSendByte(0x34);
					break;
				default:
					//SBUF = rxb;
					break;
				}
			}
		}

		/*C13265_07_img1();
        HAL_Delay(1000);
        C13265_07_img2();
        HAL_Delay(1000);
        C13265_07_img3();
        HAL_Delay(1000);
        C13265_07_img4();
        HAL_Delay(1000);*/
	}
}